<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta name="baidu-site-verification" content="UqlC4pwKIm">
  <meta name="baidu-site-verification" content="d3U0dGeqGw">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



  <meta name="google-site-verification" content="1C1XSuJ8TgM2O0mcZvsgzEdy0IdRZOJfxDYPyh18U9Q">














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.cat.net/css?family=Roboto Slab:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="系统架构,云栖社区,">










<meta name="description" content="转载自https://www.jianshu.com/p/47408eb7e6e3【只阅读学习，请勿它用】 1、业务背景随着闲鱼业务的发展，用户规模达到数亿级，用户维度的数据指标，达到上百个之多。如何从亿级别的数据中，快速筛选出符合期望的用户人群，进行精细化人群运营，是技术需要解决的问题。业界的很多方案常常需要分钟级甚至小时级才能生成查询结果。本文提供了一种解决大数据场景下的高效数据筛选、统计和分">
<meta name="keywords" content="系统架构,云栖社区">
<meta property="og:type" content="article">
<meta property="og:title" content="毫秒级从百亿大表任意维度筛选数据，是怎么做到的...">
<meta property="og:url" content="http://sangmu.wewithwe.com/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../index.html">
<meta property="og:site_name" content="隐久">
<meta property="og:description" content="转载自https://www.jianshu.com/p/47408eb7e6e3【只阅读学习，请勿它用】 1、业务背景随着闲鱼业务的发展，用户规模达到数亿级，用户维度的数据指标，达到上百个之多。如何从亿级别的数据中，快速筛选出符合期望的用户人群，进行精细化人群运营，是技术需要解决的问题。业界的很多方案常常需要分钟级甚至小时级才能生成查询结果。本文提供了一种解决大数据场景下的高效数据筛选、统计和分">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2509688-4c9f37321de88f2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/2509688-9b26c7f570b62508.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp">
<meta property="og:updated_time" content="2018-11-28T10:46:52.402Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="毫秒级从百亿大表任意维度筛选数据，是怎么做到的...">
<meta name="twitter:description" content="转载自https://www.jianshu.com/p/47408eb7e6e3【只阅读学习，请勿它用】 1、业务背景随着闲鱼业务的发展，用户规模达到数亿级，用户维度的数据指标，达到上百个之多。如何从亿级别的数据中，快速筛选出符合期望的用户人群，进行精细化人群运营，是技术需要解决的问题。业界的很多方案常常需要分钟级甚至小时级才能生成查询结果。本文提供了一种解决大数据场景下的高效数据筛选、统计和分">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/2509688-4c9f37321de88f2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: 'undefined',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://sangmu.wewithwe.com/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../">





  <title>毫秒级从百亿大表任意维度筛选数据，是怎么做到的... | 隐久</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-111723881-1', 'auto');
  ga('send', 'pageview');
</script>





</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">隐久</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://sangmu.wewithwe.com/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="隐久">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="隐久">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">毫秒级从百亿大表任意维度筛选数据，是怎么做到的...</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-11-28T18:32:39+08:00">
                2018-11-28
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2018-11-28T18:46:52+08:00">
                2018-11-28
              </time>
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/架构/" itemprop="url" rel="index">
                    <span itemprop="name">架构</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../" class="leancloud_visitors" data-flag-title="毫秒级从百亿大表任意维度筛选数据，是怎么做到的...">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>转载自<a href="https://www.jianshu.com/p/47408eb7e6e3" target="_blank" rel="noopener">https://www.jianshu.com/p/47408eb7e6e3</a>【只阅读学习，请勿它用】</p>
<h3 id="1、业务背景"><a href="#1、业务背景" class="headerlink" title="1、业务背景"></a>1、业务背景</h3><p>随着闲鱼业务的发展，用户规模达到数亿级，用户维度的数据指标，达到上百个之多。如何从亿级别的数据中，快速筛选出符合期望的用户人群，进行精细化人群运营，是技术需要解决的问题。业界的很多方案常常需要分钟级甚至小时级才能生成查询结果。本文提供了一种解决大数据场景下的高效数据筛选、统计和分析方法，从亿级别数据中，任意组合查询条件，筛选需要的数据，做到毫秒级返回。</p>
<h3 id="2、技术选型分析"><a href="#2、技术选型分析" class="headerlink" title="2、技术选型分析"></a>2、技术选型分析</h3><p>从技术角度分析，我们这个业务场景有如下特点：</p>
<ol>
<li>需要支持任意维度的组合(and/or)嵌套查询，且要求低延迟；</li>
<li>数据规模大，至少亿级别，且需要支持不断扩展；</li>
<li>单条数据指标维度多，至少上百，且需要支持不断增加；<br> 综合分析，这是一个典型的OLAP场景。</li>
</ol>
<h4 id="2-1-OLTP与OLAP"><a href="#2-1-OLTP与OLAP" class="headerlink" title="2.1 OLTP与OLAP"></a>2.1 OLTP与OLAP</h4><p>下面简单对比下OLTP和OLAP：</p>
<table>
<thead>
<tr>
<th style="text-align:left"></th>
<th style="text-align:left">OLTP</th>
<th style="text-align:left">OLAP</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">定义</td>
<td style="text-align:left">联机事务处理</td>
<td style="text-align:left">联机分析处理</td>
</tr>
<tr>
<td style="text-align:left">应用场景</td>
<td style="text-align:left">日常业务操作</td>
<td style="text-align:left">分析决策，报表统计</td>
</tr>
<tr>
<td style="text-align:left">事务要求</td>
<td style="text-align:left">需要支持事务</td>
<td style="text-align:left">无需事务支持</td>
</tr>
<tr>
<td style="text-align:left">常用数据操作</td>
<td style="text-align:left">读/写高并发</td>
<td style="text-align:left">查询为主，并发要求相对低</td>
</tr>
<tr>
<td style="text-align:left">实时性要求</td>
<td style="text-align:left">高</td>
<td style="text-align:left">要求不严格</td>
</tr>
<tr>
<td style="text-align:left">DB大小</td>
<td style="text-align:left">MB-GB</td>
<td style="text-align:left">GB-TB</td>
</tr>
<tr>
<td style="text-align:left">数据行数</td>
<td style="text-align:left">几万到几百万</td>
<td style="text-align:left">亿级别甚至几十亿上百亿</td>
</tr>
<tr>
<td style="text-align:left">数据列数</td>
<td style="text-align:left">几十至上百列</td>
<td style="text-align:left">百级别至千级别</td>
</tr>
</tbody>
</table>
<p>最常见的数据库，如MySql、Oracle等，都采用行式存储，比较适合OLTP。如果用MySql等行数据库来实现OLAP，一般都会碰到两个瓶颈：</p>
<ol>
<li>数据量瓶颈：mysql比较适合的数据量级是百万级，再多的话，查询和写入性能会明显下降。因此，一般会采用分库分表的方式，把数据规模控制在百万级。</li>
<li>查询效率瓶颈：mysql对于常用的条件查询，需要单独建立索引或组合索引。非索引字段的查询需要扫描全表，性能下降明显。</li>
</ol>
<p>综上分析，我们的应用场景，并不适合采用行存储数据库，因此我们重点考虑列存数据库。</p>
<h4 id="2-2-行式存储与列式存储"><a href="#2-2-行式存储与列式存储" class="headerlink" title="2.2 行式存储与列式存储"></a>2.2 行式存储与列式存储</h4><p>下面简单对比一下行式存储与列式存储的特点：</p>
<table>
<thead>
<tr>
<th style="text-align:left"></th>
<th style="text-align:left">行式存储</th>
<th style="text-align:left">列式存储</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">存储特点</td>
<td style="text-align:left">同一行数据一起存储</td>
<td style="text-align:left">同一列数据一起存储</td>
</tr>
<tr>
<td style="text-align:left">读取优点</td>
<td style="text-align:left">一次性读取整行数据快捷</td>
<td style="text-align:left">读取单列数据快捷</td>
</tr>
<tr>
<td style="text-align:left">读取缺点</td>
<td style="text-align:left">单列读取，也需要读取整行数据</td>
<td style="text-align:left">整行查询，需要重组数据</td>
</tr>
<tr>
<td style="text-align:left">数据更新特点</td>
<td style="text-align:left">INSERT/UPDATE比较方便</td>
<td style="text-align:left">INSERT/UPDATE比较麻烦</td>
</tr>
<tr>
<td style="text-align:left">索引</td>
<td style="text-align:left">需要单独对查询列建索引</td>
<td style="text-align:left">每一列都可以作为索引</td>
</tr>
<tr>
<td style="text-align:left">压缩特点</td>
<td style="text-align:left">同一行数据差异大，压缩比率低</td>
<td style="text-align:left">一列数据由于相似性，压缩比率高</td>
</tr>
</tbody>
</table>
<p>行存适合近线数据分析，比如要求查询表中某几条符合条件的记录的所有字段的场景。列存适合用于数据的统计分析。考虑如下场景：一个用于存放用户的表中有20个字段，而我们要统计用户年龄的平均值，如果是行存，则要全表扫描，遍历所有行。但如果是列存，数据库只要定位到年龄这一列，然后只扫描这一列的数据就可以得到所有的年龄，计算平均值，性能上相比行存理论上就会快20倍。<br>而在列存数据库中，比较常见的是HBase。HBase应用的核心设计重点是rowkey的设计，一般要把常用的筛选条件，组合设计到rowkey中，通过rowkey的get(单条记录)或者scan(范围)查询。因此HBase比较适合有限查询条件下的非结构化数据存储。而我们的场景，由于所有字段都需要作为筛选条件，所以本质上还是需要结构化存储，且要求查询低延迟，因此也无法使用HBase。<br>我们综合考虑集团内多款列式存储的DB产品(ADS/PostgreSQL/HBase/HybridDB)，综合评估读写性能、稳定性、语法完备程度及开发和部署成本，我们选择了HybridDB for MySQL计算规格来构建人群圈选引擎。</p>
<h4 id="2-3-HybridDB-for-MySQL计算规格介绍"><a href="#2-3-HybridDB-for-MySQL计算规格介绍" class="headerlink" title="2.3 HybridDB for MySQL计算规格介绍"></a>2.3 HybridDB for MySQL计算规格介绍</h4><p>HybridDB for MySQL计算规格对我们的这个场景而言，核心能力主要有：</p>
<ol>
<li>任意维度智能组合索引(使用方无需单独自建索引)</li>
<li>百亿大表查询毫秒级响应</li>
<li>MySql BI生态兼容，完备SQL支持</li>
<li>空间检索、全文检索、复杂数据类型(多值列、JSON)支持</li>
</ol>
<p>那么，HybridDB for MySQL计算规格是如何做到大数据场景下的任意维度组合查询的毫秒级响应的呢？</p>
<ul>
<li>首先是HybridDB的高性能列式存储引擎，内置于存储的谓词计算能力，可以利用各种统计信息快速跳过数据块实现快速筛选；</li>
<li>第二是HybridDB的智能索引技术，在大宽表上一键自动全索引并根据列索引智能组合出各种谓词条件进行过滤；</li>
<li>第三是高性能MPP+DAG的融合计算引擎，兼顾高并发和高吞吐两种模式实现了基于pipeline的高性能向量计算，并且计算引擎和存储紧密配合，让计算更快；</li>
<li>第四是HybridDB支持各种数据建模技术例如星型模型、雪花模型、聚集排序等，业务适度数据建模可以实现更好的性能指标。</li>
</ul>
<p>综合来说，HybridDB for MySQL计算规格是以SQL为中心的多功能在线实时仓库系统，很适合我们的业务场景，因此我们在此之上构建了我们的人群圈选底层引擎。</p>
<h3 id="3、业务实现"><a href="#3、业务实现" class="headerlink" title="3、业务实现"></a>3、业务实现</h3><p>在搭建了人群圈选引擎之后，我们重点改造了我们的消息推送系统，作为人群精细化运营的一个重要落地点。</p>
<h4 id="3-1-闲鱼消息推送简介"><a href="#3-1-闲鱼消息推送简介" class="headerlink" title="3.1 闲鱼消息推送简介"></a>3.1 闲鱼消息推送简介</h4><p>消息推送(PUSH)是信息触达用户最快捷的手段。闲鱼比较常用的PUSH方式，是先离线计算好PUSH人群、准备好对应PUSH文案，然后在第二天指定的时间推送。一般都是周期性的PUSH任务。但是临时性的、需要立刻发送、紧急的PUSH任务，就需要BI同学介入，每个PUSH任务平均约需要占用BI同学半天的开发时间，且操作上也比较麻烦。本次我们把人群圈选系统与原有的PUSH系统打通，极大地改善了此类PUSH的准备数据以及发送的效率，解放了开发资源。</p>
<h4 id="3-2-系统架构"><a href="#3-2-系统架构" class="headerlink" title="3.2 系统架构"></a>3.2 系统架构</h4><p><img src="//upload-images.jianshu.io/upload_images/2509688-4c9f37321de88f2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp" alt="image | left"></p>
<p>离线数据层：用户维度数据，分散在各个业务系统的离线表中。我们通过离线T+1定时任务，把数据汇总导入到实时计算层的用户大宽表中。</p>
<p>实时计算层：根据人群的筛选条件，从用户大宽表中，查询符合的用户数量和用户ID列表，为应用系统提供服务。</p>
<p>人群圈选前台系统：提供可视化的操作界面。运营同学选择筛选条件，保存为人群，用于分析或者发送PUSH。每一个人群，对应一个SQL存储。类似于：<br>select count(*) from user_big_table where column1&gt; 1 and column2 in (‘a’,’b’) and ( column31=1 or column32=2)<br>同时，SQL可以支持任意字段的多层and/or嵌套组合。<br>用SQL保存人群的方式，当用户表中的数据变更时，可以随时执行SQL，获取最新的人群用户，来更新人群。</p>
<p>闲鱼PUSH系统：从人群圈选前台系统中获取人群对应的where条件，再从实时计算层，分页获取用户列表，给用户发送PUSH。在实现过程中，我们重点解决了分页查询的性能问题。</p>
<p>分页查询性能优化方案：<br>在分页时，当人群的规模很大(千万级别)时，页码越往后，查询的性能会有明显下降。因此，我们采用把人群数据增加行号、导出到MySql的方式，来提升性能。表结构如下：</p>
<table>
<thead>
<tr>
<th style="text-align:left">批次号</th>
<th style="text-align:left">人群ID</th>
<th style="text-align:left">行号</th>
<th style="text-align:left">用户ID</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">1001</td>
<td style="text-align:left">1</td>
<td style="text-align:left">1</td>
<td style="text-align:left">123</td>
</tr>
<tr>
<td style="text-align:left">1001</td>
<td style="text-align:left">1</td>
<td style="text-align:left">2</td>
<td style="text-align:left">234</td>
</tr>
<tr>
<td style="text-align:left">1001</td>
<td style="text-align:left">1</td>
<td style="text-align:left">3</td>
<td style="text-align:left">345</td>
</tr>
<tr>
<td style="text-align:left">1001</td>
<td style="text-align:left">1</td>
<td style="text-align:left">4</td>
<td style="text-align:left">456</td>
</tr>
</tbody>
</table>
<ul>
<li>批次号：人群每导出一次，就新加一个批次号，批次号为时间戳，递增。</li>
<li>行号：从1开始递增，每一个批次号对应的行号都是从1到N。</li>
</ul>
<p>我们为”人群ID”+”批次号”+”行号”建组合索引，分页查询时，用索引查询的方式替换分页的方式，从而保证大页码时的查询效率。</p>
<p>另外，为此额外付出的导出数据的开销，得益于HybridDB强大的数据导出能力，数据量在万级别至百万级别，耗时在秒级至几十秒级别。综合权衡之后，采用了本方案。</p>
<h3 id="4、PUSH系统改造收益"><a href="#4、PUSH系统改造收益" class="headerlink" title="4、PUSH系统改造收益"></a>4、PUSH系统改造收益</h3><p><img src="//upload-images.jianshu.io/upload_images/2509688-9b26c7f570b62508.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp" alt="image | left"></p>
<p>undefined</p>
<p>人群圈选系统为闲鱼精细化用户运营提供了强有力的底层能力支撑。同时，圈选人群，也可以应用到其他的业务场景，比如首页焦点图定投等需要分层用户运营的场景，为闲鱼业务提供了很大的优化空间。</p>
<p>本文实现了海量多维度数据中组合查询的秒级返回结果，是一种OLAP场景下的通用技术实现方案。同时介绍了用该技术方案改造原有业务系统的一个应用案例，取得了很好的业务结果，可供类似需求或场景的参考。</p>
<h3 id="5、未来"><a href="#5、未来" class="headerlink" title="5、未来"></a>5、未来</h3><p>人群圈选引擎中的用户数据，我们目前是T+1导入的。这是考虑到人群相关的指标，变化频率不是很快，且很多指标(比如用户标签)都是离线T+1计算的，因此T+1的数据更新频度是可以接受的。后续我们又基于HybridDB构建了更为强大的商品圈选引擎。闲鱼商品数据相比用户数据，变化更快。一方面用户随时会更新自己的商品，另一方面，由于闲鱼商品单库存(售出即下架)的特性，以及其他原因，商品状态会随时变更。因此我们的选品引擎，应该尽快感知到这些数据的变化，并在投放层面做出实时调整。我们基于HybridDB(存储)和实时计算引擎，构建了更为强大的“马赫”实时选品系统。</p>
<hr>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    隐久
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://sangmu.wewithwe.com/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../" title="毫秒级从百亿大表任意维度筛选数据，是怎么做到的...">http://sangmu.wewithwe.com/2018/11/28/毫秒级从百亿大表任意维度筛选数据，是怎么做到的.../</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/系统架构/" rel="tag"># 系统架构</a>
          
            <a href="/tags/云栖社区/" rel="tag"># 云栖社区</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/11/27/闭包/" rel="next" title="什么是闭包？闭包的优缺点">
                <i class="fa fa-chevron-left"></i> 什么是闭包？闭包的优缺点
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/11/如何用形象的比喻描述大数据的技术生态？Hadoop、Hive、Spark-之间是什么关系？/" rel="prev" title="如何用形象的比喻描述大数据的技术生态？Hadoop、Hive、Spark 之间是什么关系？">
                如何用形象的比喻描述大数据的技术生态？Hadoop、Hive、Spark 之间是什么关系？ <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="隐久">
            
              <p class="site-author-name" itemprop="name">隐久</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

			<!--my custom code begin-->
			<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
			<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.5.0/velocity.min.js"></script>
			<script type="text/javascript">
			  $("#sidebar").hover(function(){
				$("#mydivshow").velocity('stop').velocity({opacity: 1});
			  },function(){
				$("#mydivshow").velocity('stop').velocity({opacity: 0});
			  });
			</script>
			<div id="mydivshow" class="mydivshow">
			<!--my custom code end-->
			
          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/yourname" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://gitee.com/yourname" target="_blank" title="Gitee">
                    
                      <i class="fa fa-fw fa-glide"></i>Gitee</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yourname @gmail.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://plus.google.com/" target="_blank" title="Google">
                    
                      <i class="fa fa-fw fa-google"></i>Google</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.weibo.com/" target="_blank" title="微博">
                    
                      <i class="fa fa-fw fa-weibo"></i>微博</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.zhihu.com/people/yourname" target="_blank" title="知乎">
                    
                      <i class="fa fa-fw fa-bell"></i>知乎</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://me.csdn.net/helloniou" title="CSDN博客主页" target="_blank">CSDN博客主页</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yingjiu.github.io" title="全球站主页" target="_blank">全球站主页</a>
                  </li>
                
              </ul>
            </div>
          

          <div id="player1" class="aplayer"></div>
<script src="/js/src/APlayer.min.js"></script>
<script type="text/javascript">
var ap = new APlayer({
    element: document.getElementById('player1'),                       // Optional, player element
    narrow: false,                                                     // Optional, narrow style
    autoplay: false,                                                    // Optional, autoplay song(s), not supported by mobile browsers
    showlrc: 0,                                                        // Optional, show lrc, can be 0, 1, 2, see: ###With lrc
    mutex: true,                                                       // Optional, pause other players when this player playing
    theme: '#e6d0b2',                                                  // Optional, theme color, default: #b7daff
    mode: 'random',                                                    // Optional, play mode, can be `random` `single` `circulation`(loop) `order`(no loop), default: `circulation`
    preload: 'metadata',                                               // Optional, the way to load music, can be 'none' 'metadata' 'auto', default: 'auto'
    listmaxheight: '513px',                                             // Optional, max height of play list
    music: {                                                           // Required, music info, see: ###With playlist
        title: '黑色幽默',                                          // Required, music title
        author: 'cover',                          // Required, music author
        url: 'http://www.ytmp3.cn/down/55230.mp3',  // Required, music url
        pic: '/images/visitor.jpg',  // Optional, music picture
    }
});
</script>
        </div>
		<!--my custom code begin-->
		</div>
		<!--my custom code end-->
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、业务背景"><span class="nav-number">1.</span> <span class="nav-text">1、业务背景</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、技术选型分析"><span class="nav-number">2.</span> <span class="nav-text">2、技术选型分析</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-OLTP与OLAP"><span class="nav-number">2.1.</span> <span class="nav-text">2.1 OLTP与OLAP</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-行式存储与列式存储"><span class="nav-number">2.2.</span> <span class="nav-text">2.2 行式存储与列式存储</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-HybridDB-for-MySQL计算规格介绍"><span class="nav-number">2.3.</span> <span class="nav-text">2.3 HybridDB for MySQL计算规格介绍</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、业务实现"><span class="nav-number">3.</span> <span class="nav-text">3、业务实现</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-闲鱼消息推送简介"><span class="nav-number">3.1.</span> <span class="nav-text">3.1 闲鱼消息推送简介</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-系统架构"><span class="nav-number">3.2.</span> <span class="nav-text">3.2 系统架构</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4、PUSH系统改造收益"><span class="nav-number">4.</span> <span class="nav-text">4、PUSH系统改造收益</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5、未来"><span class="nav-number">5.</span> <span class="nav-text">5、未来</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">隐久</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count"></span>
  
</div>






  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a></div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>




  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("", "");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
  </script>

  

  
  


  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.3"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.3"></script>


  
  <script type="text/javascript" src="/js/src/exturl.js?v=5.1.3"></script>


  <script src="/js/src/Aplayer-Controler.js"></script>
<div id="AP-controler"></div>
<script type="text/javascript">
var myapc=new APlayer_Controler({
		APC_dom:$('#AP-controler'),
		aplayer:ap, //此为绑定的aplayer对象
		attach_right:false,
		position:{top:'300px',bottom:''},
		fixed:true,
		btn_width:100,
		btn_height:120,
		img_src:['http://oty1v077k.bkt.clouddn.com/bukagirl.jpg',
				'http://oty1v077k.bkt.clouddn.com/jumpgirl.jpg',
				'http://oty1v077k.bkt.clouddn.com/pentigirl.jpg',
				'http://oty1v077k.bkt.clouddn.com/%E8%90%8C1.gif'],
		img_style:{repeat:'no-repeat',position:'center',size:'contain'},
		ctrls_color:'rgba(173,255,47,0.8)',
		ctrls_hover_color:'rgba(255,140,0,0.7)',
		tips_on:true,
		tips_width:140,
		tips_height:25,
		tips_color:'rgba(255,255,255,0.6)',
		tips_content:{},
		timeout:30
	});
</script>
  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>



</body>
</html>
